# -*- coding: utf-8 -*-
"""
Created on Sun May 24 09:48:39 2015

@author: kelvin
"""
 
import ConfigParser

conf = ConfigParser.ConfigParser()
conf.read("test.conf")

print conf.options("section1")
print conf.items("section1")


# 获取指定的section， 指定的option的值
print conf.get("section1", "name")
print conf.get("section1", "age")
print conf.get("section2", "ip")
print conf.get("section2", "port")

#获取所有的section
sections = conf.sections()
print sections

#写配置文件

# 更新指定section, option的值
conf.set("section2", "port", "8081")

# 写入指定section, 增加新option的值
conf.set("section2", "IEPort", "8000")

# 添加新的 section
#conf.add_section("new_section")
#conf.set("new_section", "new_option", "http://www.cnblogs.com/tankxiao")

#删除指定的option和section
#conf.remove_option("new_section","new_option")
#conf.remove_section("new_section")

# 写回配置文件，任何改变生效都需要重新写回
#conf.write(open("test.conf","w"))







